
<template>
    <div class="port-page">
    	<div class="but1">
		<router-link to="/home">
			<el-button type="warning" size="small"   style='margin-right: 10px;' icon="el-icon-menu">首页</el-button>
		</router-link>
    <!-- <el-button type="success"  size="small"  @click='componentsShow("add")'  icon="el-icon-edit">添加</el-button> -->
	     </div>
        <!-- 顶部按钮 -->
        <!-- 模糊搜索条件 -->
        <div class="search">

            <div class="search-item">
                <!--<span>关键字</span>-->
                <el-input placeholder="请选择资源库" class="code-search" v-model="vkeyword"  @keyup.enter.native="search" icon="search"></el-input>
            </div>
            <el-button  type="primary"  class="add btn" style="border-radius:13px;" :loading="searchLoading" @click="search" icon="el-icon-search" ></el-button>

            <el-button type="danger" class="add btn" :disabled="multipleDeleteDisabled" v-if="false" icon="delete" @click="componentsShow('multipleDelete','')">批量删除</el-button>
        </div>
        <div class="cz">
          <div class="cz1">
            <div class="sp1">阶段</div>
            <div class="sp2">
              <el-tabs type="border-card" v-model="tabPosition" @tab-click="handleClick" style="margin-bottom: 30px;">
               <el-tab-pane label="线上互动" name='1'>线上互动</el-tab-pane>
               <el-tab-pane label="预约" name='2'>预约</el-tab-pane>
               <el-tab-pane label="试听跟踪" name='3'>试听跟踪</el-tab-pane>
               <el-tab-pane label="报名跟踪" name='4'>报名跟踪</el-tab-pane>
               <el-tab-pane label="完成" name='5'>完成</el-tab-pane>
             </el-tabs>
           </div>
          </div>
          <div class="cz1">
            <div class="sp1">标签</div>
            <div class="bq">
  						<el-tag type="success" class="list1"   v-for="(v,index) in bqList">
  							{{v}}
  						<i class="el-icon-close del1" @click = "delbq(v)"></i>
  						</el-tag>
  					  <el-button type="" size="small" @click="componentsShow('bq')">+标签</el-button>
  					</div>
          </div>
          <div class="cz1">
            <div class="sp1">操作</div><div class="sp2">
              <el-button type="success"  size="small"  @click='search()' >刷新</el-button>
              <el-button type="success"  size="small"  @click='componentsShow("add")' >添加计划</el-button>
            </div>
          </div>
        </div>
        <!-- 数据表格展示区域 -->
        <el-table
            :data="dataList"
            border
            align="center"
            class="admin-table"
            @select="checkSelect"
            @select-all="checkall">
            <!-- <el-table-column type="selection" width="55"></el-table-column> -->
            <div slot='empty'>
                <img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
                <span style="vertical-align: middle;">暂时还没有内容哦!</span>
            </div>
            <el-table-column
                :prop="v.prop"
                :label="v.label"
                v-for="(v,index) in portTitleList"
                align="center"
                show-overflow-tooltip
                v-if="v.hide != 0"
                :formatter="v.formatter"
                :align="v.align || 'center'"
                :fixed="v.fixed"
                :class-name="v.columnStyle"
                :width="v.width"
                :min-width="v.minWidth"
                :header-align="v.headerAlign || 'center'"
                >
                <template scope="scope">
                    <div slot="reference" :style="tableCellControl(scope)">
                        {{ scope.row[scope.column.property] }}
                    </div>
                 </template>
            </el-table-column>
			<el-table-column label="操作"  width="200" align="center">
                <template scope="scope">
                    <!-- v-if="scope.row.qx == 'Y'"-->
                    <el-button size="small" type="text"  @click="componentsShow('edit',scope)">编辑</el-button>
                    <el-button size="small" type="text"  @click="componentsShow('muban',scope)">浏览模板</el-button>
                    <el-button size="small" type="text"  @click="componentsShow('info',scope)">分享</el-button>
                    <el-button size="small" type="text" @click="componentsShow('singleDelete',scope)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页查询区域 -->
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="pageindex"
            :page-sizes="pagesizes"
            :page-size="pagesize"
            :layout="layout"
            :total="total"
            class="class-page">
        </el-pagination>
        <!-- 各个组件显示区域 -->
        <!-- 动画加载 -->
        <LoadingComponent v-show="isLoading"></LoadingComponent>
        <!-- 添加组件 -->
        <AddComponent v-if="portComponents.add.toggle" @close="componentsHide" :params="this.jdid"></AddComponent>
        <!-- 编辑组件 -->
        <EditComponent v-if="portComponents.edit.toggle" @close="componentsHide" :params="portComponents.edit.params"></EditComponent>
        <!-- info组件 -->
        <infoComponent v-if="portComponents.info.toggle" @close="componentsHide" :params="portComponents.info.params"></infoComponent>

        <mubanComponent v-if="portComponents.muban.toggle" @close="componentsHide" :params="portComponents.muban.params"></mubanComponent>
        <!-- 单独删除组件 -->
        <DeleteComponent v-if="portComponents.singleDelete.toggle"  @close="componentsHide"  :data="portComponents.singleDelete.data"></DeleteComponent>
        <!-- 批量删除组件 -->
        <DeleteComponent v-if="portComponents.multipleDelete.toggle"  @close="componentsHide"  :data="portComponents.multipleDelete.data"></DeleteComponent>
        <!-- 子路由显示区域 -->
        <BqComponent v-if="portComponents.bq.toggle" @close="componentsHide" :params="portComponents.bq.params"></BqComponent>

        <router-view class="port-view"></router-view>
    </div>
</template>
<script>
    import { mapState } from 'vuex'
    import LoadingComponent from 'components/loading'
    import AddComponent from './add'
    import EditComponent from './edit'
    import InfoComponent from './info'
    import mubanComponent from './muban'
    import DeleteComponent from './del'
    import BqComponent from '../../admin/xxjbszManage/bq'
    import qs from 'qs'
    export default {
        components: { LoadingComponent, DeleteComponent, AddComponent, EditComponent,InfoComponent ,BqComponent,mubanComponent},
        data () {
            return {

            /*模糊搜索条件*/
              tabPosition: '1',
               vkeyword:'', // 关键字
               xsmc:'', // 关键字
               kcmc:'', // 关键字
               bqList:[],
				multipleDelNum:'', //获取批量选择的数据
                dataList: [],  //表格数据
                comboxlist:[], //下拉框 动态的
                vcomautovalue:'',//下拉框name 动态的
                vcomgdvalue:'',//下拉框name 固定的

				/*动画加载*/
                isLoading: true,//动画加载
                searchLoading: false,//搜索按钮触发按钮动画
                /*分页属性设置*/
                layout: 'total, sizes, prev, pager, next, jumper',//组件布局
			    pageindex: this.$store.state.pageindex,//当前分页页码
                pagesizes: this.$store.state.pagesizes,//显示个数的选择器选项
                pagesize: this.$store.state.pagesize,//每页显示条目数
                total: 0,//总条数

                /*组件区域*/
                portComponents: {
                    /* 单行删除  */
                    singleDelete: {
                        type: 'singleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'single',
                            title: '此操作将删除该记录?, 是否继续?'
                        }
                    },
                    /* 批量删除 */
                    multipleDelete: {
                        type: 'multipleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'multiple',
                            title: '此操作将删除您选中的记录?, 是否继续?'
                        }
                    },
                    /* 添加 */
                    add: {
                        type: 'add',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    /* 编辑 */
                    edit: {
                        type: 'edit',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    bq: {
          						type: 'bq',
          						toggle: false,
          						params: '',
          						data: {}
          					},
                    /* info */
                    info: {
                        type: 'info',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    muban: {
                        type: 'muban',
                        toggle: false,
                        params: '',
                        data: {}
                    }
                },
                /*
                    prop :  接口参数名
                    label : 接口中文名
                    hide : 是否隐藏这一列
                    align : 这一列对齐顺序 ： left,right,center
                    headerAlign : 这一列表头对齐方式 ： left,right,center
                */
                portTitleList: [

                    {
                        prop:'xh',
                        label:'序号 ',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'60',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },


                    {
                        prop:'mc',
                        label:'主题',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'jdmc',
                        label:'计划阶段',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'bq',
                        label:'标签',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },

                    {
                        prop:'bz',
                        label:'备注',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },


                ]
            }
        },
        created () {
            //加载页面时调用
            this.$store.dispatch('changeTitle','资料库');//修改title
            this.$store.dispatch('changeRouterIndex','/Marketing/zlk');//修改路由
            this.search();//分页获取默认数据
            // this.getcomlist(); //加载下拉列表
            this.isLoading = true;//动画开始
        },
        mounted () {
            //加载完成之后event
            this.isLoading = false;//动画结束
        },
        methods: {
          handleClick(tab, event){
            console.log(tab, event);
            this.search();//分页获取默认数据
          },
          delbq(bq){
    				var dd =[];
  					for ( let i in this.bqList ) {
  						if (this.bqList[i]==bq){
  							continue}else{
  							 dd.push(this.bqList[i]);
  						}
  					}
  					this.bqList= dd;
  			 },
          search () {
		    //查询搜索触发事件
            var logininfo = JSON.parse(localStorage.logininfo) ;
            var params3 = qs.stringify({
              bq:this.bqList,
              keyword: this.vkeyword, // 关键字
              jdid:this.tabPosition,
              yhid:logininfo.id,
              xxid:logininfo.xxid,
              pageindex: this.pageindex,
              pagesize: this.pagesize
						});
              this.searchLoading = true;
              this.axios.post(this.$store.state.api + 'ziliao/list',params3)
              .then( res => {
                  console.log(res,111)
                  let data = res.data.data;
                  let list = data.list;
                  this.total = data.totalPage;
                  this.jdid = res.data.data.jdid
                  this.dataList = list;
                  this.searchLoading = false;
              }).catch( res => {
                  console.log(res)
                  this.searchLoading = false;
              })
          },
          getcomlist(){
          /*  var logininfo = JSON.parse(localStorage.logininfo) ;
            this.axios.get(this.$store.state.api + 'dome/list',{
                params:{
                    yhid:logininfo.id,
                    xxid:logininfo.xxid
                }
            }).then( res => {
                console.log(res)
                let data = res.data.data;
                let list = data.list;
                this.total = data.totalPage;
                this.dataList = list;
                this.searchLoading = false;
            }).catch( res => {
            })  */
          } ,
          tableCellControl (scope) {
            //表格单元格控制CSS样式
                /*if (scope.row.id == 112 && scope.column.property == "iname") {
                    return {
                        color:"red",
                    }
                }else{
                    return {
                        color:"green",
                    }
                }*/
           },
           handleSizeChange (val) {//每页显示条数触发事件
                this.pagesize = val;
                this.pageindex = 1;
                this.search();
            },
            handleCurrentChange (val) {//分页触发事件
                this.search();
            },
            checkSelect (selection, row) {//点击单选select触发事件
                console.log(selection, row)
                let strID = [];
                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                this.multipleDelNum = strID.join(",");
            },
            checkall (selection) {//点击全选select触发事件
                let strID = [];
                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                this.multipleDelNum = strID.join(",");
            },
            /* 组件的弹框  */
            componentsShow (type,data) { //显示组件
                console.log(type,data)
                for ( let i in this.portComponents ) {
                    if (type == this.portComponents[i].type) {
                        this.portComponents[i].toggle = true;
                        this.portComponents[i].params = data;
                        if (this.portComponents[i].data.type == 'single') {
                            this.portComponents[i].data.index = data.row.id
                        }else if(this.portComponents[i].data.type == 'multiple'){
                            this.portComponents[i].data.index = this.multipleDelNum;
                        }else{
                            return;
                        }
                        return;
                    }
                }
            },
            componentsHide (setting) { //关闭组件
                console.log(setting)
                for ( let i in this.portComponents ) {
                    if (setting.type == this.portComponents[i].type) {
                        this.portComponents[i].toggle = false;
                        if (this.portComponents[i].type=='bq'){
                           if (!setting.cancel) {
                              for ( let b in setting.clist ) {

                            this.bqList.push( setting.clist[b]);
                           }

                           }
                        }else{
                         if (!setting.cancel) {
                           this.search();
                         }
                        }
                        return;
                    }
                }
            }
        },
        computed: {
            ...mapState([
                'api'//域名
            ]),
            multipleDeleteDisabled () {
                console.log(this.multipleDelNum)
                if (this.multipleDelNum) {
                    return false;
                }else{
                    return true
                }
            }
        }
    }
</script>

<style lang="less" scoped>
.cz{
  width: 100%;
  background: #fff;
  float: left;
  .cz1{
      // border: 1px solid #E6EBF5;
      height: 40px;
      line-height: 40px;
      color: #878D99;
      font-size: 15px;
      overflow: hidden;
      border-bottom: 1px solid #E6EBF5;
      .sp1{
          width: 10%;
          float: left;
          // border: 1px solid #E6EBF5;
          border-right:  1px solid #E6EBF5;
          text-align: center;
      }
      .sp2{
          width: 90%;
          // border: 1px solid #E6EBF5;
          float: left;
      }

  }
}
    .port-page {
        font-size:12px;
        .btn {
            height: 30px;
            padding:0 10px;
        }
        .code-search {
            height: 30px;
            margin:10px 0 10px 0;
            min-width: 120px;
			max-width: 150px;
        }
        .class-page {
            text-align: left;
            margin-top:10px;
        }
        .search-item {
            display: inline-block;
            margin-right:10px;
        }
        .but1{
			width: 50%;
			float: left;
			margin-top: 8px;
		}
		.search{
			width: 50%;
			float: right;
			text-align: right;
		}
    }
</style>
